﻿using MovingChameLibrary.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MovingChameLibrary.DataManager
{
    public class TourData
    {
        private static TourData current;
        public static TourData Current
        {
            get
            {
                if (current == null)
                    current = new TourData();
                return current;
            }
        }

        private List<Tour> _viewedTours = new List<Tour>();
        public List<Tour> ViewedTours
        {
            get { return this._viewedTours; }
            set { this._viewedTours = value; }
        }

        private CurrentTour _currentTour;
        public CurrentTour CurrentTour
        {
            get { return _currentTour; }
            set { _currentTour = value; }
        }

        public static Location GetLocation(string uniqueId)
        {
            IEnumerable<Location> matches = TourData.Current.ViewedTours.SelectMany(tour => tour.Locations.Items).Where(location => location.UniqueId.Equals(uniqueId));
            if (matches.Count() >= 1) return matches.First();
            return default(Location);
        }

        public static Location GetCurrentTourLocation(string uniqueId)
        {
            var matches = TourData.Current.CurrentTour.Locations.Items.Where(location => location.Id.Equals(uniqueId));
            if (matches.Count() == 1) return matches.First();
            return default(Location);
        }

        public static Photo GetPhoto(string uniqueId)
        {
            IEnumerable<Photo> matches = TourData.Current.ViewedTours.SelectMany(tour => tour.Photos.Items).Where(album => album.UniqueId.Equals(uniqueId));
            if (matches.Count() >= 1) return matches.First();
            return default(Photo);
        }

        public static Tour GetTour(string uniqueId)
        {
            IEnumerable<Tour> matches = TourData.Current.ViewedTours.Where(tour => tour.UniqueId.Equals(uniqueId));
            if (matches.Count() >= 1) return matches.First();

            return default(Tour);
        }
    }
}